package org.wishwork.api.allocate.query;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import org.wishwork.api.ExtendBase;

import java.util.List;

/**
 * @description: 调拨单查询
 * @author: WangYX
 * @create: 2022-04-12 21:18
 * @Version: 1.0.0
 **/
@Getter
@ToString
@EqualsAndHashCode
public class AllocateQueryRequest extends ExtendBase {

    /**
     * 非必填
     * 指定线上订单号，和时间段不能同时为空
     */
    private List<String> soIds;


    /**
     * 非必填
     * 调拨单号
     */
    private List<String> ioIds;

    private AllocateQueryRequest(Integer pageIndex,
                                 Integer pageSize,
                                 String modifiedBegin,
                                 String modifiedEnd,
                                 List<String> soIds,
                                 List<String> ioIds) {
        super(pageIndex, pageSize, modifiedBegin, modifiedEnd);
        this.ioIds = ioIds;
        this.soIds = soIds;
    }

    @Override
    public Builder toBuilder() {
        return new Builder().pageIndex(this.pageIndex)
                .pageSize(this.pageSize)
                .modifiedBegin(this.modifiedBegin)
                .modifiedEnd(this.modifiedEnd)
                .ioIds(this.ioIds)
                .soIds(this.soIds);
    }

    public static Builder builder() {
        return new Builder();
    }


    public static class Builder extends ExtendBase.Builder<Builder, AllocateQueryRequest> {

        private List<String> soIds;
        private List<String> ioIds;

        @Override
        public Builder modifiedBegin(String modifiedBegin) {
            this.modifiedBegin = modifiedBegin;
            return this;
        }

        @Override
        public Builder modifiedEnd(String modifiedEnd) {
            this.modifiedEnd = modifiedEnd;
            return this;
        }

        @Override
        public Builder pageIndex(Integer pageIndex) {
            this.pageIndex = pageIndex;
            return this;
        }

        @Override
        public Builder pageSize(Integer pageSize) {
            this.pageSize = pageSize;
            return this;
        }

        public Builder soIds(List<String> soIds) {
            this.soIds = soIds;
            return this;
        }

        public Builder ioIds(List<String> ioIds) {
            this.ioIds = ioIds;
            return this;
        }

        @Override
        public AllocateQueryRequest build() {
            this.pageIndex = this.pageIndex == null ? 1 : this.pageIndex < 0 ? 1 : this.pageIndex;
            this.pageSize = this.pageSize == null ? 30 : this.pageSize < 0 ? 30 : this.pageSize;
            if (this.soIds == null || this.soIds.size() <= 0) {
                keyIsEmptyTimeHandle(7);
            }
            modifiedTimeHandle(7);
            return new AllocateQueryRequest(this.pageIndex, this.pageSize, this.modifiedBegin, this.modifiedEnd,
                    this.soIds, this.ioIds);
        }
    }
}
